// 添加 cookie 封装
export const setCookie = (name, value, expiryDate) => {
    let currentDate = new Date();
    currentDate.setDate(currentDate.getDate() + expiryDate);
    document.cookie = name + '=' + value + '; expires=' + currentDate;
};
// 查找 cookie 封装
export const getCookie = name => {
    let arr = document.cookie.split('; ');
    for (let i = 0; i < arr.length; i++) {
        let arr2 = arr[i].split('=');
        if (arr2[0] === name) {
            return arr2[1];
        }
    }
    return '';
};
// 删除 cookie 封装
export const removeCookie = name => {
    setCookie(name, 1, -1);
};

// localStorage
export const myStorage = {
    //存储
    set(key, value) {
        localStorage.setItem(key, JSON.stringify(value));
    },
    //取出数据
    get(key) {
        try {
            const value = localStorage.getItem(key);
            if (value === null || value === undefined || value === "") {
                return null;
            }
            return JSON.parse(localStorage.getItem(key));
        } catch (err) {
            return null
        }
    },
    // 删除数据
    remove(key) {
        localStorage.removeItem(key);
    }
}
// sessionStorage
export const mySession = {
    //存储
    set(key, value) {
        sessionStorage.setItem(key, JSON.stringify(value));
    },
    //取出数据
    get(key) {
        try {
            const value = sessionStorage.getItem(key);
            if (value === null || value === undefined || value === "") {
                return null;
            }
            return JSON.parse(sessionStorage.getItem(key));
        } catch (err) {
            return null
        }
    },
    // 删除数据
    remove(key) {
        sessionStorage.removeItem(key);
    }
}
